package br.com.salao.rest;

import java.util.HashMap;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import br.com.salao.bean.Login;
import br.com.salao.model.LoginModel;


@Path("/login")
public class LoginService {

	public LoginService(){}

	@GET
	@Path("/{usuario}/{senha}")	
	@Produces({MediaType.APPLICATION_JSON})
	public HashMap<String, HashMap<String, Boolean>> efetuaLogin(@PathParam("usuario")String usuario, @PathParam("senha")String senha){
	
		System.out.println(usuario);
		System.out.println(senha);
		
		HashMap<String, Boolean> hashAcesso = new HashMap<String, Boolean>();
		
		Login loginBean = new Login();
		loginBean.setLogin(usuario);
		
		LoginModel loginModel = new LoginModel();
		loginBean = loginModel.buscarLogin(loginBean.getLogin());
		
		if(loginBean.getSenha().equals(senha) && loginBean.isAtivo() == true){
			hashAcesso.put(loginBean.getLogin(), true);
		}else{
			hashAcesso.put(loginBean.getLogin(), false);
		}						
		
		HashMap<String, HashMap<String, Boolean>> hashLogin = new HashMap<String, HashMap<String, Boolean>>();
		hashLogin.put("login", hashAcesso);		
		
		return hashLogin;
	}
	
	@GET
	@Path("/id/{usuario}/{senha}")	
	@Produces({MediaType.APPLICATION_JSON})
	public HashMap<String, Integer> obterIdLogin(@PathParam("usuario")String usuario, @PathParam("senha")String senha){
	
		System.out.println(usuario);
		System.out.println(senha);
		
		HashMap<String, Integer> hashAcesso = new HashMap<String, Integer>();
		
		Login loginBean = new Login();
		loginBean.setLogin(usuario);
		
		LoginModel loginModel = new LoginModel();
		loginBean = loginModel.buscarLogin(loginBean.getLogin());
		
		if(loginBean.getSenha().equals(senha) && loginBean.isAtivo() == true){
			hashAcesso.put(loginBean.getLogin(), loginBean.getId());
		}else{
			hashAcesso.put(loginBean.getLogin(), loginBean.getId());
		}	

		return hashAcesso;
	}
}
